package edu.ynu.e_platform.dao;

import edu.ynu.e_platform.common.dao.LogicDAO;
import edu.ynu.e_platform.entities.Customer;
import edu.ynu.e_platform.entities.Order;
import edu.ynu.e_platform.entities.Shop;
import edu.ynu.e_platform.entities.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author manwen Yang
 */
@Component
public interface OrderDao extends LogicDAO<Order, Long> {

    List<Order> findByCustomer(Customer customer);

    List<Order> findByShop(Shop shop);

    List<Order> findByCustomerAndStatus(Customer customer, Integer status);

    @Query(value = "select o from torders o where o.customer = :customer and o.status = :status")
    Page<Order> pageFind(@Param("customer")Customer customer, @Param("status")Integer status, Pageable pageable);

    @Query(value = "select o from torders o where o.customer = :customer and o.status in (1,2) ")
    Page<Order> pageFindPay(@Param("customer")Customer customer, Pageable pageable);
}
